/**
 * Copyright (C) 2011 Denatics Development
 * 
 * Programmed by David Tiersch <dtiersch@denatics.com>
 * 
 * This file is part of B0mberman.
 * 
 * B0mberman is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * B0mberman is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with B0mberman. If not, see <http://www.gnu.org/licenses/>.
 */
package com.denatics.bomberman.tools;

import com.denatics.bomberman.Config;

/**
 * This class centralizes the general Debug-Output.
 * 
 * @author David Tiersch <dtiersch@denatics.com>
 */
public abstract class Debugger {

    /**
     * Separator used in Debug-Outputs.
     */
    private static final String SEP = ":";

    /**
     * Closing of the Line-number.
     */
    private static final String LINECLOS = "] ";

    /**
     * Debug-Level.
     */
    public enum LEVEL {
        /**
         * No Debug-Output.
         */
        OFF,
        /**
         * Only Errors.
         */
        ERROR,
        /**
         * Informations.
         */
        INFO,
        /**
         * All output.
         */
        DEBUG;
    };

    /**
     * Empty, private constructor to forbid Creating an Instance of this class.
     */
    private Debugger() {
        // do nothing
    }

    /**
     * Prints a message on std_err.
     * 
     * @param message
     *            Message to be printed
     */
    public static void printError(final String message) {
        if (Config.DEBUG != LEVEL.OFF) {
            Throwable throwable = new Throwable();
            String originClass = (throwable.getStackTrace())[1].getClassName();
            int originLine = (throwable.getStackTrace())[1].getLineNumber();

            System.err.println("Error: [" + originClass + SEP + originLine
                    + LINECLOS + message);
        }
    }

    /**
     * Prints a message on std_out.
     * 
     * @param message
     *            Message to be printed
     */
    public static void printInfo(final String message) {
        if (Config.DEBUG == LEVEL.DEBUG) {
            Throwable throwable = new Throwable();
            String originClass = (throwable.getStackTrace())[1].getClassName();
            int originLine = (throwable.getStackTrace())[1].getLineNumber();
            System.out.println("Info: [" + originClass + SEP + originLine
                    + LINECLOS + message);
        }
        if (Config.DEBUG == LEVEL.INFO) {
            System.out.println(message);
        }
    }

    /**
     * Prints a message on std_out.
     * 
     * @param message
     *            Message to be printed
     */
    public static void printDebug(final String message) {
        if (Config.DEBUG == LEVEL.DEBUG) {
            Throwable throwable = new Throwable();
            String originClass = (throwable.getStackTrace())[1].getClassName();
            int originLine = (throwable.getStackTrace())[1].getLineNumber();

            System.out.println("Debug: [" + originClass + SEP + originLine
                    + LINECLOS + message);
        }
    }
}
